package logic

import (
	"context"
	"product_zc/models/mysql"

	"product_zc/productRpc/internal/svc"
	"product_zc/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PrefectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPrefectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PrefectLogic {
	return &PrefectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PrefectLogic) Prefect(in *productRpc.PrefectRequest) (*productRpc.PrefectResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{}
	mysql.DB.Where("id=?", in.UserId).Find(&user)

	user.NickName = in.NickName
	user.HeadImage = in.Image
	user.Ads = in.Ads

	mysql.DB.Create(&user)

	return &productRpc.PrefectResponse{
		Id: int64(user.ID),
	}, nil
}
